package com.hivekion.system.controller;

import com.hivekion.system.domain.vo.database.SysDataBaseTableColumnVo;
import com.hivekion.system.domain.vo.database.SysDataBaseTableVo;
import com.hivekion.system.service.ISysDataBaseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据库表
 *
 * @author guoying
 */
@RestController
@RequestMapping("/system/dataBase")
public class SysDataBaseController {

    @Autowired
    private ISysDataBaseService sysDataBaseService;

    @ApiOperation("数据库表信息查询")
    @GetMapping("/getTableList")
    public List<SysDataBaseTableVo> getTableList() {
        List<SysDataBaseTableVo> list = sysDataBaseService.selectTableList();
        return list;
    }

    @ApiOperation("数据库表结构查询")
    @GetMapping("/getColumnList")
    public List<SysDataBaseTableColumnVo> getColumnList(String tableName) {
        List<SysDataBaseTableColumnVo> list = sysDataBaseService.selectTableColumnList(tableName);
        return list;
    }

    @ApiOperation("数据库表数据导出")
    @PostMapping("/export")
    public void export(String tableName, HttpServletResponse response) {
        sysDataBaseService.export(tableName, response);
    }

}
